package DBase.Players;

import DBase.Coordinate;
import DBase.Board;

/**
 * 
 * @author Elya & Dana
 */
public class ComputerPlayer extends Player {
    
    
    /**
     * Places a ship on board randomly for a computer player
     * @param row row for placing the ship
     * @param col column for placing the ship
     * @param directionArr direction of placing(Horizontal or Vertical)
     * @param shipSize the ship size
     * returns the parameters to the arrays: row[0],col[0],directionArr[0]
     */
    public void PlaceShipsOnBoard(int [] row, int [] col, int [] directionArr, int shipSize){
       
       double tmpX = Math.random();
       double tmpY = Math.random();
       
       switch(shipSize){
           case 5:  col[0] = (int)(tmpX * 5);
                    row[0] = (int)(tmpY * 2);
                    directionArr[0] = 1;
                    break;
           case 4:  col[0] = (int)(tmpX * 6);
                    row[0] = (int)(tmpY * 2) + 2;
                    directionArr[0] = 1;
                    break;
           case 3:  col[0] = (int)(tmpX * 7);
                    row[0] = (int)(tmpY * 2) + 4;
                    directionArr[0] = 1;
                    break;
           case 2:  col[0] = (int)(tmpX * 8);
                    row[0] = (int)(tmpY * 2) + 6;
                    directionArr[0] = (int)(tmpX * 2) + 1;
                    break;
           default:
       }
    }
     
    /**
     * Computer player function to bomb a rivals cell in their board
     * @param boardNum the board number of another player
     * @return Coordinate
     */
    public Coordinate getBombSquare(int boardNum){
        
        boolean flag=false;
        Coordinate c = new Coordinate();
        String mark;
        Board board = rivalBoards[boardNum];
        int x,y;
        
        double tmpX = Math.random();
        double tmpY = Math.random();
       
        x = (int)(tmpX * 10);
        y = (int)(tmpY * 10);
                            
        mark = board.GetGameBoard()[x][y].getMark();
        if(mark.compareTo(" ") == 0 || mark.compareTo("o") == 0){
            flag = true;
            c = new Coordinate(x,y);
        }
        return c; 
    }
    
    /**
     * Gets a random board number
     * @param PlayerBoardNumber current player board number
     * @param PlayersNumber the players turn in the game
     * @return integer 
     */
    public int getBoardNum(int PlayerBoardNumber,int PlayersNumber){
        
        double randomNum;
        int boardNum = PlayerBoardNumber;
        
        while(boardNum == PlayerBoardNumber){
            randomNum = Math.random();
            boardNum = (int)(randomNum * PlayersNumber);
        }
        return (boardNum + 1);
    }
    
    /**
     * Function for choosing option 3 in the game which means attack a coordinate
     * @return computer's choice which is always 3
     */
    public int getChoice(){
        
         return 3;
    }
}
